package com.triones.api.controller.web.interlace;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.ApplyVipRecordDO;
import com.triones.api.entity.MemberDO;
import com.triones.api.entity.interlace.dto.InterlaceMemberDO;
import com.triones.api.entity.interlace.vo.CustomInterlaceMemberVO;
import com.triones.api.entity.interlace.vo.InterlaceMemberVO;
import com.triones.api.entity.param.ApplyVipRecordParams;
import com.triones.api.entity.param.MemberParams;
import com.triones.api.entity.vo.CustomApplyVipRecordVO;
import com.triones.api.entity.vo.CustomMemberVO;
import com.triones.api.entity.vo.MemberVO;
import com.triones.api.service.interlace.InterlaceMemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/interlace/member")
public class InterlaceMemberController extends BaseController {

    private final InterlaceMemberService interlaceMemberService;

    /**
     * 用户列表（分页）
     */
    @SaCheckPermission("system:member:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<CustomInterlaceMemberVO> pageList(InterlaceMemberDO dto, PageQuery pageQuery) {
        return interlaceMemberService.pageList(dto, pageQuery);
    }

    /**
     * 用户详情
     */
    @SaCheckPermission("system:member:query")
    @GetMapping("/detail/{id}")
    public R<CustomInterlaceMemberVO> getDetail(@PathVariable("id") Long id) {
        return R.ok(interlaceMemberService.getDetail(id));
    }

    /**
     * 禁用/解除禁用
     */
    @SaCheckPermission("system:member:prohibit")
    @PutMapping("/prohibit")
    public R<Void> prohibit(@RequestBody InterlaceMemberDO dto) {
        return toAjax(interlaceMemberService.prohibit(dto));
    }

    /**
     * 会员用户列表（分页）
     */
    @SaCheckPermission("system:memberVip:pageList")
    @GetMapping("/vip/pageList")
    public TableDataInfo<CustomInterlaceMemberVO> vipPageList(InterlaceMemberDO dto, PageQuery pageQuery) {
        dto.setIsVip("1");
        return interlaceMemberService.pageList(dto, pageQuery);
    }

    /**
     * 系统添加会员用户
     */
    @SaCheckPermission("system:memberVip:setVip")
    @PutMapping("/sysSetVip")
    public R<Void> sysSetVip(@Validated @RequestBody InterlaceMemberDO dto) {
        return toAjax(interlaceMemberService.sysSetVip(dto));
    }

    /**
     * 会员申请列表（分页）
     */
    @SaCheckPermission("system:vipApply:pageList")
    @GetMapping("/vipApply/pageList")
    public TableDataInfo<CustomApplyVipRecordVO> vipApplyPageList(ApplyVipRecordDO dto, PageQuery pageQuery) {
        return interlaceMemberService.vipApplyPageList(dto, pageQuery);
    }

    /**
     * 审核会员申请
     */
    @SaCheckPermission("system:vipApply:audit")
    @PutMapping("/vipApply/audit")
    public R<Void> auditVipApply(@Validated @RequestBody ApplyVipRecordDO dto) {
        return toAjax(interlaceMemberService.auditVipApply(dto));
    }

    /**
     * 用户列表
     */
    @GetMapping("/list")
    public R<List<InterlaceMemberVO>> list() {
        return R.ok(interlaceMemberService.list());
    }

    /**
     * 资产刷新
     */
    @SaCheckPermission("system:member:moneyRefresh")
    @GetMapping("/refreshMoney/{id}")
    public R<Void> refreshMoney(@PathVariable("id") Long id) {
        return toAjax(interlaceMemberService.refreshMoney(id));
    }
}
